package com.smart.campus.school.service.impl;

import com.smart.campus.common.core.text.Convert;
import com.smart.campus.common.utils.DateUtils;
import com.smart.campus.common.utils.security.Md5Utils;
import com.smart.campus.school.domain.ClassInfo;
import com.smart.campus.school.domain.Wisdom;
import com.smart.campus.school.mapper.ClassInfoMapper;
import com.smart.campus.school.mapper.WisdomMapper;
import com.smart.campus.school.service.IClassInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 班级信息Service业务层处理
 * 
 * @author Zhihe.Li
 * @date 2020-05-13
 */
@Service
public class ClassInfoServiceImpl implements IClassInfoService
{
    @Autowired
    private ClassInfoMapper classInfoMapper;
    @Autowired
    private WisdomMapper wisdomMapper;

    /**
     * 查询班级信息
     * 
     * @param id 班级信息ID
     * @return 班级信息
     */
    @Override
    public ClassInfo selectClassInfoById(Long id)
    {

        Wisdom wisdom = new Wisdom();
        wisdom.setClassId(id);

        List<Wisdom> wisdoms = wisdomMapper.selectWisdomList(wisdom);
        ClassInfo classInfo = classInfoMapper.selectClassInfoById(id);
        if(classInfo != null){
            classInfo.setWisdomList(wisdoms);
            return classInfo;
        }
        return null;
    }

    /**
     * 查询班级信息列表
     * 
     * @param classInfo 班级信息
     * @return 班级信息
     */
    @Override
    public List<ClassInfo> selectClassInfoList(ClassInfo classInfo)
    {
        return classInfoMapper.selectClassInfoList(classInfo);
    }

    /**
     * 新增班级信息
     * 
     * @param classInfo 班级信息
     * @return 结果
     */
    @Override
    public int insertClassInfo(ClassInfo classInfo)
    {
        classInfo.setCreateTime(DateUtils.getNowDate());
        classInfo.setStatus(1);
        return classInfoMapper.insertClassInfo(classInfo);
    }

    /**
     * 修改班级信息
     * 
     * @param classInfo 班级信息
     * @return 结果
     */
    @Override
    public int updateClassInfo(ClassInfo classInfo)
    {
        classInfo.setCreateTime(DateUtils.getNowDate());
        return classInfoMapper.updateClassInfo(classInfo);
    }

    /**
     * 删除班级信息对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteClassInfoByIds(String ids)
    {
        return classInfoMapper.deleteClassInfoByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除班级信息信息
     * 
     * @param id 班级信息ID
     * @return 结果
     */
    @Override
    public int deleteClassInfoById(Long id)
    {
        return classInfoMapper.deleteClassInfoById(id);
    }

    @Override
    public ClassInfo login(String classId, String password) {

        ClassInfo classInfo = selectClassInfoById(Long.valueOf(classId));



        return classInfo;
    }


}
